import React,{Component} from 'react';
import { Icon, Input, Button, Table, Pagination, message } from 'antd';
import { Link } from 'react-router-dom';
import './index.less';
import Bread from '../../common/Bread/index';
import axios from 'axios';
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'


const Search = Input.Search;
class MyorganizationManage extends React.Component {
	constructor(props){
		super(props)
		this.state = {
			data:[],
			page:['10','20','30','40','50','60','70','80','90'],
			page_1: 1,
			limit: 10,
		}
	}
	columns = [{
		title: '组织名称',
		dataIndex: '组织名称',
		key: '组织名称',
	  }, {
		title: '身份',
		dataIndex: '身份',
		key: '身份',
	  }, {
		title: '加入时间',
		dataIndex: '加入时间',
		key: '加入时间',
		}];
	onShowSizeChange=(current, pageSize)=> {
		console.log(current, pageSize);
		this.getData(current, pageSize);
		this.setState({
			limit: pageSize
		})
	}
	onChange=(pageNumber)=> {
	  console.log('Page: ', pageNumber);
	  this.getData(pageNumber);
	}
	getData= (page,limit=this.state.limit)=>{
		const _this = this;
		const Token = localStorage.getItem("token");
		axios({
			method: 'get',
			url: '/api/customer/baasorg/org/all',
			headers: {
				'Content-Type': 'application/json',
				Authorization:Token,
			},
			params:{
				page: page,
				limit: limit
			}
		})
		.then(function (response) {
			let data = [];
			response.data&&response.data.data&&response.data.data.rows&&response.data.data.rows.forEach((e,i)=>{
				if(e.leaderStatus == 0){
					e.leaderStatus = '组织者'
				}else {
					e.leaderStatus = '用户'
				}
				data.push({
					key: i+'',
					"组织名称": e.orgName,
					"身份": e.leaderStatus,
					"加入时间": e.crtTime,
				})
			})
			_this.setState({
				data: data,
				totalnum:response.data.data.total,
			})
			// console.log(response);
		})
		.catch(function (error) {
			console.log(error)
		});
		
	}	
	componentWillMount(){
		this.getData(this.state.page_1,this.state.limit);
	}
	
	render() {
		return (
				<div>
					<Bread bread={['组织管理',['查看我的组织','accountService/MyorganizationManage']]}/>
					<div className="index-buttons">
						<Link to="/accountService/UserList"><Button type="primary">进入组织管理</Button></Link>
					</div>
					<Table 
						columns={this.columns} 
						dataSource={this.state.data} 
						bordered
						pagination={false} />
						<div className="page_foot">
							<span className="data_num">共{this.state.totalnum}条</span>
							<Pagination 
								pageSizeOptions={this.state.page} 
								className="page" 
								showSizeChanger 
								showQuickJumper
								onShowSizeChange={this.onShowSizeChange} 
								defaultCurrent={1} 
								total={this.state.totalnum} 
								onChange={this.onChange} />
						</div>
				</div>
					
		);
	}
}

export default MyorganizationManage;

